using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Woz
{
    /// <summary>
    /// the add image action adds an image to the screen
    /// </summary>
    internal class AddImageAction : Woz.Action
    {
        /// <summary>
        /// default constructor
        /// </summary>
        /// <param name="pFilename">the filename of the image to add</param>
        /// <param name="pPosition">the position to add the image to</param>
        public AddImageAction(string pFilename, Point pPosition)
        {
            // set the filename
            this.mFilename = pFilename;

            // set the position
            this.mPosition = pPosition;

            // create the woz image
            this.mImage = new Woz.Image(this.mFilename, this.mPosition);

            // make action string
            this.mActionString = String.Concat("Added ", this.mImage.ToString());
        }

        /// <summary>
        /// gets the name of the tool this action prefers
        /// </summary>
        public override string ToolName
        {
            get
            {
                return "Image";
            }
        }

        /// <summary>
        /// gets whether this action can be propagated or not
        /// </summary>
        public override bool Propagatable
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        /// adds the image to the screen
        /// </summary>
        /// <param name="pScreen">the screen to the image to</param>
        protected override void OnExecute(Woz.Screen pScreen)
        {
            // add this image to the current screen
            pScreen.AddEntity(this.mImage, true);

            // request an update from the selected screen
            Woz.ScreenManager.Instance.RequestSelectedScreenUpdate(pScreen, this.mImage.BoundingBox);
        }

        /// <summary>
        /// removes the image from the screen
        /// </summary>
        /// <param name="pScreen">the screen to remove the image from</param>
        protected override void OnUnExecute(Woz.Screen pScreen)
        {
            // remove this image from the current screen
            pScreen.RemoveEntity(this.mImage, true);

            // request an update from the selected screen
            Woz.ScreenManager.Instance.RequestSelectedScreenUpdate(pScreen, this.mImage.BoundingBox);
        }

        /// <summary>
        /// check to see if this action can be applied to the given screen
        /// </summary>
        /// <param name="pScreen">the screen to check against</param>
        /// <returns>true if the action can be applied to the given screen</returns>
        public override bool CanApplyTo(Woz.Screen pScreen)
        {
            return true;
        }

        /// <summary>
        /// the filename of the image
        /// </summary>
        private string mFilename;

        /// <summary>
        /// the position to place the image
        /// </summary>
        private Point mPosition;

        /// <summary>
        /// the image this action refers to
        /// </summary>
        private Woz.Image mImage;
    }
}
